package day021.homework.p7;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class TcpClient {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 8888);
        OutputStream out = socket.getOutputStream();

        FileInputStream fis = new FileInputStream("D:\\ideaProjects\\javase_code\\study-practice\\src" +
                "\\day021\\tcp\\files\\123.jpg");
        byte[] buf = new byte[1024];
        int len = 0;
        while ((len = fis.read(buf)) != -1) {
            out.write(buf, 0, len);
        }

        socket.shutdownOutput();
        System.out.println(out);

        InputStream in = socket.getInputStream();
        len = in.read(buf);
        System.out.println(new String(buf, 0, len));

        socket.close();
        fis.close();
    }
}
